package com.oauth.twitter.client.ui;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.oauth.twitter.client.beans.Tweet;

public class TweetsPanel extends Composite {

	private static TweetsPanelUiBinder uiBinder = GWT.create(TweetsPanelUiBinder.class);

	interface TweetsPanelUiBinder extends UiBinder<Widget, TweetsPanel> {
	}

	@UiField
	VerticalPanel tweetsPanel;

	public TweetsPanel() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	public void addTweet(List<Tweet> pTweets) {
		for (Tweet tweet : pTweets) {
			addTweet(tweet, false);
		}
	}

	public void addTweet(Tweet pTweet, boolean pAddAtBegining) {
		TweetPanel tweetPanel = new TweetPanel();
		tweetPanel.initTweetPanel(pTweet);
		if (pAddAtBegining) {
			tweetsPanel.insert(tweetPanel, 0);
		} else {
			tweetsPanel.add(tweetPanel);
		}
	}

}
